<template>
	<view class="content">
		<view class="topBg">
			
		</view>
		<view class="tabs-box">
					<u-tabs :list="list"  :activeStyle="activeStyle" :itemStyle="itemStyle"
			:lineColor="`url(${lineBg}) 100% 100%`" lineWidth="42rpx" lineHeight="12rpx"
			@click="tabSetCurrent" :scrollable="false"></u-tabs>
		</view>
		<view class="" style="padding: 0 20rpx;">
			<messageList :list="massagrsList" />
		</view>

		<Loading/>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[{
					name:'消息',
					type:'Text'
				},
				{
					name:'通知',
					type:'Notice'
				},
				{
					name:'公告',
					type:'Announcement'
				},
				{
					name:'新闻',
					type:'News'
				}],
				lineBg:'',
				type:'Text',
				activeStyle:{
					fontSize:'36rpx',
					color:'#z	',	
				},
				itemStyle:{
					fontSize:'32rpx',
					fontWeight:'700',
					color:'#333333',
					height:'100rpx'
				},
				massagrsList:[],
				page:1
			}
		},
		onLoad() {
			this.upData()
		},
		onReachBottom(){
			this.upData()
		},
		methods: {
			upData(){
				if(!this.page) return;
				this.$myRequest('/api/messages',{type:this.type,pageIndex:this.page}).then(res=>{
					res.data.forEach(item=>{
						item.content=JSON.parse(item.content)
					})	
					this.massagrsList.push(...res.data)
					if(res.data.length===10){
						this.page++
					}else{
						this.page=0
					}
				})
			},
			tabSetCurrent(e){
				this.type=e.type
				this.page=1
				this.massagrsList=[]
				this.upData()
			},
		}
	}
</script>

<style lang="scss">
	.content{
		background-color: #F5F5F5;
		padding: 160rpx 0 0 0;
		min-height: calc(100vh - 160rpx);
		.card{
			padding: 32rpx 40rpx;
		}
	}
	.tabs-box{
		background-color: #ffffff;
		padding-bottom: 10rpx;
	}
	.topBg{
		background-image: linear-gradient(42deg,#3E60FC,#65ADFF);
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 160rpx;
		z-index: 99;
	}

</style>
